package com.xx.jicheng.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xx.jicheng.entity.Account;
import com.xx.jicheng.mapper.AccountMapper;
import com.xx.jicheng.service.AccountService;
import com.xx.jicheng.service.SecurityService;

@Service
@Transactional
public class AccountServiceImpl implements AccountService {
	
	@Autowired
	private SecurityService securityService;
	
	@Autowired
	private AccountMapper accountMapper;

	@Override
	public boolean checkAccountExists(String account) {
		return accountMapper.checkAccountExists(account);
	}

	@Override
	public boolean checkCellphoneExists(String cellphone) {
		return accountMapper.checkCellphoneExists(cellphone);
	}

	@Override
	public void register(Account account) {
		String salt = securityService.generateSalt(8);		
		String pass = securityService.encrypt(account.getPassword(), salt);
		account.setSalt(salt);
		account.setPassword(pass);
		accountMapper.save(account);
	}

}
